package com.sakura.system.controller.config;

import com.sakura.system.utils.JwtInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * 拦截器配置
 * 页面拦截和放行
 */

public class WebConfig implements WebMvcConfigurer {

//    引入拦截器
    @Resource
    private JwtInterceptor jwtInterceptor;

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer){
        // 指定controller 统一的接口前缀,相当于 sakura
//        configurer.addPathPrefix("/console", clazz -> clazz.isAnnotationPresent(RestController.class));
    }

    // 加载拦截器,设置拦截规则
    @Override
    public void addInterceptors(InterceptorRegistry registry){
//        拦截前面,后面不拦截(登陆，注册)
//        registry.addInterceptor(jwtInterceptor).addPathPatterns("/console/**").excludePathPatterns("/console/login").excludePathPatterns("/console/register");
        registry.addInterceptor(jwtInterceptor).addPathPatterns("/api/console/**").excludePathPatterns("/api/console/login").excludePathPatterns("/api/console/register");
    }

}
